package com.per.other.until;

import java.util.Base64;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.context.support.WebApplicationObjectSupport;

import com.per.hjh.model.User;
import com.per.hjh.service.UserService;
import com.per.hjh.service.impl.UserServiceImpl;

import cn.org.rapid_framework.util.holder.ApplicationContextHolder;




public class UserHelper {

	
public static boolean login(User loginUser,HttpServletRequest request) 
{
	WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); 

	UserService userService=(UserService) wac.getBean("userServiceImpl");
	
	User vUser = userService.selectByUserName(loginUser.getUserName());
	
	
	if(vUser!=null && vUser.getPassword().equals(loginUser.getPassword()))
	{
		HttpSession session = request.getSession(true);
		session.setAttribute("loginUser", vUser);
		return true;
	}
	
	return false;
}
//获取当前用户
public static User getLoginUser(HttpServletRequest request)
{
	HttpSession session = request.getSession();
	return (User)session.getAttribute("loginUser");
}
}
